package com.zy.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.Vo.GoodsVo;
import com.zy.Vo.PageAto;
import com.zy.mapper.GoodsMapper;
import com.zy.pojo.Goods;
import com.zy.service.GoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Wrapper;
import java.util.List;

@Service("goodsService")
public class GoodsServiceImpl implements GoodsService {
    @Resource
    private GoodsMapper goodsMapper;
    @Override
    public PageAto getPageGoodsList(Integer pageSize, Integer pageNo, GoodsVo goodsVo) {
        Page page = new Page();
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like(!StringUtils.isEmpty(goodsVo.getName()),"name",goodsVo.getName())
                .like(!StringUtils.isEmpty(goodsVo.getType()),"type",goodsVo.getType());
        List<Goods> list = goodsMapper.getGoodsPageList(page, queryWrapper);
        System.out.println(page.getTotal()+"+++++++++++++++++++++++++");
        return new PageAto(list,page.getTotal());
    }

    @Override
    public void getGoodsDelete(Integer id) {
    goodsMapper.deleteById(id);
    }
}
